package cn.itsource.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.itsource.constants.RConst;
import cn.itsource.pojo.domain.DriverAuthMaterial;
import cn.itsource.mapper.DriverAuthMaterialMapper;
import cn.itsource.pojo.myenum.DriverAuthEnum;
import cn.itsource.pojo.ro.RealAuthRo;
import cn.itsource.service.IDriverAuthMaterialService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 司机实名资料 服务实现类
 * </p>
 *
 * @author zcj
 * @since 2024-07-02
 */
@Service
public class DriverAuthMaterialServiceImpl extends ServiceImpl<DriverAuthMaterialMapper, DriverAuthMaterial> implements IDriverAuthMaterialService {

    @Override
    public void realAuth(RealAuthRo realAuthRo) {
        //干嘛？
        //查询当前审核的记录
        DriverAuthMaterial material = super.getById(realAuthRo.getId());
        //判断是否审核通过
        if(realAuthRo.getApprove()){
            //true
            auth(material, DriverAuthEnum.AUTH_SUCCESS, realAuthRo);
            //发送短信
        }else {
            //false
            auth(material, DriverAuthEnum.AUTH_NO_PASS, realAuthRo);
            //发送短信
        }
    }

    @Override
    public void realAuthCancel(RealAuthRo realAuthRo) {
        DriverAuthMaterial material = super.getById(realAuthRo.getId());
        material.setRealAuthStatus(DriverAuthEnum.TO_DO_AUTH.getStatus());
        material.setAuditTime(new Date());
        material.setAuditUserId(Long.valueOf(StpUtil.getLoginId().toString()));
        material.setAuditRemark(realAuthRo.getRemark());
        material.setUpdateTime(new Date());
        super.updateById(material);
    }

    @Override
    public Boolean getDriverStatus() {
        //逻辑是啥
        //司机id  1前端传2StpUtil取3StpUtil.getExtra()
        DriverAuthMaterial byId = super.getById(Long.valueOf(StpUtil.getLoginId().toString()));
        return  byId != null && byId.getRealAuthStatus() == DriverAuthEnum.AUTH_SUCCESS.getStatus();
    }

    private void auth(DriverAuthMaterial material, DriverAuthEnum authSuccess, RealAuthRo realAuthRo) {
        material.setRealAuthStatus(authSuccess.getStatus());
        material.setAuditTime(new Date());
        material.setAuditUserId(Long.valueOf(StpUtil.getLoginId().toString()));
        material.setAuditRemark(realAuthRo.getRemark());
        material.setDriverId(Long.valueOf(realAuthRo.getId()));
        super.updateById(material);
    }
}
